class Solution {
public:
    int tribonacci(int n) {

        if (n == 0) return 0;
        if (n == 1 || n == 2) return 1;
        vector<int> dp(n + 1);
        dp[0] = 0, dp[1] = dp[2] = 1;
        for (int i = 3; i <= n; i++)
        {
            dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
        }
        return dp[n];
    }
};
class Solution {
public:
    int waysToStep(int n) {
        vector<int> dp(n + 1);
        if (n == 1 || n == 2) return n;
        const int MOD = 1e9 + 7;
        dp[1] = 1, dp[2] = 2, dp[3] = 4;
        for (int i = 4; i <= n; i++)
            dp[i] = ((dp[i - 1] + dp[i - 2]) % MOD + dp[i - 3]) % MOD;
        return dp[n];

    }
};
class Solution {
public:
    string largestNumber(vector<int>& nums) {
        vector<string> strs;
        for (auto e : nums) strs.push_back(to_string(e));
        sort(strs.begin(), strs.end(), [](string& s1, string& s2) {
            return s1 + s2 > s2 + s1;
            });
        string ret;
        for (auto e : strs) ret += e;
        if (ret[0] == '0') return "0";
        return ret;
    }
};
class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        int left = 0, right = 0;
        int ret = 0;
        for (int i = 0; i < n - 1; i++)
        {
            right = nums[i + 1] - nums[i];
            if (right == 0) continue;
            if (left * right <= 0) ret++;
            left = right;
        }
        return ret + 1;

    }
};